var code = "";
$(function () {
    if (window.location.href.indexOf("code") != -1) {
        code = window.location.href.split("code=")[1].split("&state")[0];
    }
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/getActivityLevel",
        type: "POST",
        data: {"code": code},
        success: function (data) {
            if (data == '' || data == null) {
                window.location.href = Feng.ctxPath + "/integralMallWeixin/activityLevelTwo";
                return false;
            }
            document.getElementById("openId").value = data.openId;
            document.getElementById("id").value = data.id;
            var html =
                "<div class=\"faction-navigation\">\n" +
                "        <div class=\"faction-navigation-left\" ></div>\n" +
                "        <div class=\"faction-navigation-title\">活跃度兑换</div>\n" +
                "        <div class=\"faction-navigation-right\"></div>\n" +
                "    </div> \n" +
                "    <div class=\"faction-content\"> \n" +
                "        <div class=\"faction-content-score\">\n" +
                "            <div class=\"score-title\">请选择您需要兑换的东西</div>\n" +
                "            <div class=\"score-tips\">积分"+data.score+"：" +
                "<input name=\"score\" type=\"radio\" value=\"积分"+data.score+"\" checked=\"checked\"/></div>\n" +
                "            <div class=\"score-tips\">返现"+data.moey+"：" +
                "<input name=\"score\" type=\"radio\" value=\"返现"+data.moey+"\" /></div>\n" +
                "        </div> \n" +
                "        <div class=\"faction-content-btn\">\n" +
                "            <button id=\"btn-selection\" type=\"button\" class=\"layui-btn layui-btn-fluid\" onclick=\"submissionScore()\">提交</button>\n" +
                "        </div>\n" +
                "    </div>";
            $("#satisfaction").html(html);
        },
        error: function (data) {

        }
    });
});

function submissionScore() {//  提交
    var openId = $("#openId").val();
    var id = $("#id").val();
    var score = $("input[name='score']:checked").val();
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/activityLevelAdd",
        type: "post",
        data: {
            "openId": openId,
            "score": score,
            "id": id
        },
        success: function (data) {
            Feng.success("兑换成功!");
            window.location.href = Feng.ctxPath + "/integralMallWeixin/personalCenter"
        }
    });
}